package com.wzcl.app.dao.repository;

import com.wzcl.app.dao.model.CourseTeacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface  CourseTeacherRepository extends JpaRepository<CourseTeacher,Integer>, JpaSpecificationExecutor<CourseTeacher> {

    List<CourseTeacher> findAllByCourseId(Integer id);

    @Modifying
    @Query("UPDATE CourseTeacher m SET m.name = ?1,m.headIcon = ?2 WHERE m.userId = ?3")
    void setNameAndHeadIconByUserId(String name, String headIcon, Integer userId);

    //查询当前教师的所有课程id
    @Query("select ct.courseId from CourseTeacher ct where ct.userId = ?1")
    List<Integer> findAllByUserId(Integer userId);
}
